﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UrlHelper.cs" company="">
//   
// </copyright>
// <summary>
//   The url helper.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace NetworkSupervisor.Helper
{
    using System;
    using System.Text;

    /// <summary>The url helper.</summary>
    public static class UrlHelper
    {
        #region Public Methods and Operators

        /// <summary>The url encode.</summary>
        /// <param name="str">The str.</param>
        /// <returns>The <see cref="string"/>.</returns>
        public static string UrlEncode(string str)
        {
            StringBuilder sb = new StringBuilder();
            byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str); // 默认是System.Text.Encoding.Default.GetBytes(str)
            for (int i = 0; i < byStr.Length; i++)
            {
                sb.Append(@"%" + Convert.ToString(byStr[i], 16));
            }

            return sb.ToString();
        }

        #endregion
    }
}